package polsense.filemerger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

import de.vdheide.mp3.MP3File;

/* MP3Index.java
 * Created on Oct 12, 2005
 * Copyright 2005 Pablo J. Lopez
 */

/**
 * @author Pablo J. Lopez
 */
public class MP3Index {

	public MP3Index() {
		col = new HashMap();
	}
	
	public MP3Index(int capacity) {
		col = new Hashtable(capacity);
	}
	
	
	private Map col;

	
	
	public void addEntry(String file, long crc){
		Long lcrc = new Long(crc);
		if(col.containsKey(lcrc))
		{
		Collection matches = (Collection) col.get(lcrc);
		matches.add(file);
			
		}else {
			Collection newCol = new ArrayList();
			newCol.add(file);
			col.put(lcrc,newCol);
		}
		
	
	
	}
	
	
	public int countMultipleInstances(){
		
		
		return getDuplicates().size();
		
		
	}
	
	
	public Collection getDuplicates(){
		int count = 0;
		Iterator it = col.values().iterator();
		Collection duplicates = new ArrayList();
		while (it.hasNext()) {
			Collection element = (Collection) it.next();
			if(element.size()>1)
			{	count++;
				duplicates.add(element);
			}	
		}
		
		return duplicates;
		
		
	}  
	
	public Collection getNonDuplicates(){
		int count = 0;
		Iterator it = col.values().iterator();
		Collection nonDuplicates = new ArrayList();
		while (it.hasNext()) {
			Collection element = (Collection) it.next();
			if(element.size()==1)
			{	count++;
				nonDuplicates.add(element);
			}	
		}
		
		return nonDuplicates;
		
		
	}
	
	
}
